package ar.edu.utn.frsf.tpae.a2013.g04.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ar.edu.utn.frsf.tpae.a2013.g04.persistence.dao.UsuarioDAO;
import ar.edu.utn.frsf.tpae.a2013.g04.persistence.model.Usuario;
import ar.edu.utn.frsf.tpae.a2013.g04.service.LogInService;

@Repository
public class LogInServiceImp implements LogInService {

	private UsuarioDAO usuarioDAO;
	
	
	public UsuarioDAO getUsuarioDAO() {
		return usuarioDAO;
	}
	
	@Autowired(required = true)
	public void setUsuarioDAO(UsuarioDAO usuarioDAO) {
		this.usuarioDAO = usuarioDAO;
	}
	
	@Override
	public Usuario logIn(String nickname, String password) {
		try {
			Usuario ret = this.usuarioDAO.buscarPorNickname(nickname);
			if(ret != null && ret.getPassword().equals(password)){
				return ret;
			}
			return null;
		}
		catch (RuntimeException e) {
			e.printStackTrace();
			return null;
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}

		
	}

/*	@Override
	public Integer logInTwo(String nickname, String password) {
		Integer rcode= new Integer(0);
		
		try {
			Usuario ret = this.usuarioDAO.buscarPorNickname(nickname);
			if(ret != null && ret.getPassword().equals(password)){
				rcode= 0;
			}
			else {
				rcode= -1;
			}
		}
		catch (RuntimeException e) {
			e.printStackTrace();
			rcode= -2;
		}
		
		catch (Exception e) {
			e.printStackTrace();
			rcode= -3;
		}
		
		return rcode;
	}*/
	
}
